using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Phoenix.ActionResults;
using Phoenix.Filters;
using Phoenix.Framework;

namespace Phoenix.Tests.Framework
{
    public class TestActionDescriptor : IActionDescriptor
    {
        readonly Func<ActionResult> actionResult;

        public TestActionDescriptor(Func<ActionResult> actionResult, IControllerDescriptor controllerDescriptor)
        {
            ControllerDescriptor = controllerDescriptor;
            this.actionResult = actionResult;
        }

        public Task Task { get; private set; }

        public Task<ActionResult> Execute(IController controller, ControllerActionContext controllerActionContext)
        {
            var task = Task.Factory.StartNew(actionResult);
            Task = task;
            return task;
        }

        public IEnumerable<FilterAttribute> GetFilterAttributes(bool cacheAttributeInstances)
        {
            return new FilterAttribute[0];
        }

        public IControllerDescriptor ControllerDescriptor { get; private set; }
    }
}